<<<<<<< HEAD
package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
=======
package com.itheima.health.controller;/*
 *@date:created in 2019/7/29
 *@description
 *@version:1.0
 */

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
>>>>>>> 6693e98994950fffdaffe5b5f8491e5db91a2da2
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
<<<<<<< HEAD
=======
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
>>>>>>> 6693e98994950fffdaffe5b5f8491e5db91a2da2
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

<<<<<<< HEAD
import java.util.List;

/**
 * @Author:hujunwei
 * @Description:权限控制器
 * @Date:2019/7/29
 * @Version:1.0
=======
/**
 * @author ：seanyang
 * @date ：Created in 2019/7/30
 * @description ：权限控制器类
 * @version: 1.0
>>>>>>> 6693e98994950fffdaffe5b5f8491e5db91a2da2
 */
@RestController
@Slf4j
@RequestMapping("/permission")
public class PermissionController {
    @Reference
    private PermissionService permissionService;
<<<<<<< HEAD

    /*
     * @Author:hujunwei
     * @功能:查询权限列表，用于页面权限信息列表展示
     * @date: 2019/7/29
     * @param
     * @return com.itheima.health.entity.Result
     */
    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Permission> permissions = permissionService.findAll();
            return new Result(true,"查询权限信息成功",permissions);
            } catch (Exception e) {
                e.printStackTrace();
            return new Result(true,"查询权限信息失败");
            }
    }

    @RequestMapping("/findPermissionIdsByRoleId")
    public Result findPermissionIdsByRoleId(Integer id){//这里的id要与前端页面传递过来的参数一摸一样
        try {
            List<Integer> permissionIds = permissionService.findPermissionByRoleId(id);
            return new Result(true,"返回权限ids成功",permissionIds);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"返回权限ids失败");
=======
    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPage")
    //@PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult=null;
        try {
           pageResult = permissionService.pageQuery(queryPageBean.getCurrentPage(),queryPageBean.getPageSize(),queryPageBean.getQueryString());
            return pageResult;
        }catch (Exception e){
            e.printStackTrace();
            return new PageResult(0l,null);
        }
    }
    /**
     * 新增权限
     * @param permission
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){
        try {
            System.out.println(permission);
            permissionService.add(permission);
            return new Result(true,MessageConst.ACTION_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConst.ACTION_FAIL);
        }
    }
    /**
     * 修改权限
     * @param permission
     * @return
     */
    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission permission){
        try {
            permissionService.edit(permission);
            return new Result(true,MessageConst.ACTION_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConst.ACTION_FAIL);
        }
    }
    /**
     * 根据id查询权限
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
        Permission permission = permissionService.findById(id);
            return new Result(true,MessageConst.ACTION_SUCCESS,permission);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConst.ACTION_FAIL);
        }
    }
    /**
     * 基于ID，删除权限
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public Result delete(Integer id){
        try {
            permissionService.delete(id);
            return new Result(true,MessageConst.ACTION_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConst.ACTION_FAIL);
>>>>>>> 6693e98994950fffdaffe5b5f8491e5db91a2da2
        }
    }
}
